{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c2694352",
   "metadata": {},
   "source": [
    "* 时间：2022-10-25/week10 \n",
    "* 记录人：阳"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e1121740",
   "metadata": {},
   "source": [
    "# 上周回顾\n",
    "> 1.while循环：while Ture--->无限循环\n",
    ">> 1. 指定次数，while Ture 可以实现for循环的指定次数，增加一个count计数器即可。\n",
    ">> 2. while Ture 一般与 用户输入 一起使用，让用户可以重复输入，知道某些条件成立结束输入（购物车）\n",
    "> 2.购物车实践（已完成）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "63af334a",
   "metadata": {},
   "source": [
    "# 本周学习内容\n",
    ">1.元组\n",
    ">\n",
    ">2.集合\n",
    ">\n",
    ">3.字典"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1a6fbfd9",
   "metadata": {},
   "source": [
    "# 1.元组（tuple）\n",
    "> 1.元组基本内容\n",
    "> \n",
    "> 2.元组的性质\n",
    ">> 1.有序性(indexing，sliceing)\n",
    ">>\n",
    ">> 2.<font color=\"red\">**不可变性**</font>,元组没有：增删改\n",
    ">\n",
    "> 2.元组的一般方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "725d825f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1800001, 1800002, 1800003) <class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "网三_学号 = (1800001,1800002,1800003)\n",
    "print(网三_学号,type(网三_学号))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "2e67d14b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1800001, 1800002, 1800003) <class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "网二_学号 = 1800001,1800002,1800003\n",
    "print(网二_学号,type(网二_学号))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "d8245889",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1800001"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_学号[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "40e97951",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1800002, 1800003)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网二_学号 [1:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "22de9390",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2022, tm_mon=10, tm_mday=25, tm_hour=15, tm_min=6, tm_sec=47, tm_wday=1, tm_yday=298, tm_isdst=0)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 元组的实际案例\n",
    "import time\n",
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "65bb611b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on struct_time object:\n",
      "\n",
      "class struct_time(builtins.tuple)\n",
      " |  struct_time(iterable=(), /)\n",
      " |  \n",
      " |  The time value as returned by gmtime(), localtime(), and strptime(), and\n",
      " |  accepted by asctime(), mktime() and strftime().  May be considered as a\n",
      " |  sequence of 9 integers.\n",
      " |  \n",
      " |  Note that several fields' values are not the same as those defined by\n",
      " |  the C language standard for struct tm.  For example, the value of the\n",
      " |  field tm_year is the actual year, not year - 1900.  See individual\n",
      " |  fields' descriptions for details.\n",
      " |  \n",
      " |  Method resolution order:\n",
      " |      struct_time\n",
      " |      builtins.tuple\n",
      " |      builtins.object\n",
      " |  \n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __reduce__(...)\n",
      " |      Helper for pickle.\n",
      " |  \n",
      " |  __repr__(self, /)\n",
      " |      Return repr(self).\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Static methods defined here:\n",
      " |  \n",
      " |  __new__(*args, **kwargs) from builtins.type\n",
      " |      Create and return a new object.  See help(type) for accurate signature.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data descriptors defined here:\n",
      " |  \n",
      " |  tm_gmtoff\n",
      " |      offset from UTC in seconds\n",
      " |  \n",
      " |  tm_hour\n",
      " |      hours, range [0, 23]\n",
      " |  \n",
      " |  tm_isdst\n",
      " |      1 if summer time is in effect, 0 if not, and -1 if unknown\n",
      " |  \n",
      " |  tm_mday\n",
      " |      day of month, range [1, 31]\n",
      " |  \n",
      " |  tm_min\n",
      " |      minutes, range [0, 59]\n",
      " |  \n",
      " |  tm_mon\n",
      " |      month of year, range [1, 12]\n",
      " |  \n",
      " |  tm_sec\n",
      " |      seconds, range [0, 61])\n",
      " |  \n",
      " |  tm_wday\n",
      " |      day of week, range [0, 6], Monday is 0\n",
      " |  \n",
      " |  tm_yday\n",
      " |      day of year, range [1, 366]\n",
      " |  \n",
      " |  tm_year\n",
      " |      year, for example, 1993\n",
      " |  \n",
      " |  tm_zone\n",
      " |      abbreviation of timezone name\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data and other attributes defined here:\n",
      " |  \n",
      " |  n_fields = 11\n",
      " |  \n",
      " |  n_sequence_fields = 9\n",
      " |  \n",
      " |  n_unnamed_fields = 0\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Methods inherited from builtins.tuple:\n",
      " |  \n",
      " |  __add__(self, value, /)\n",
      " |      Return self+value.\n",
      " |  \n",
      " |  __contains__(self, key, /)\n",
      " |      Return key in self.\n",
      " |  \n",
      " |  __eq__(self, value, /)\n",
      " |      Return self==value.\n",
      " |  \n",
      " |  __ge__(self, value, /)\n",
      " |      Return self>=value.\n",
      " |  \n",
      " |  __getattribute__(self, name, /)\n",
      " |      Return getattr(self, name).\n",
      " |  \n",
      " |  __getitem__(self, key, /)\n",
      " |      Return self[key].\n",
      " |  \n",
      " |  __getnewargs__(self, /)\n",
      " |  \n",
      " |  __gt__(self, value, /)\n",
      " |      Return self>value.\n",
      " |  \n",
      " |  __hash__(self, /)\n",
      " |      Return hash(self).\n",
      " |  \n",
      " |  __iter__(self, /)\n",
      " |      Implement iter(self).\n",
      " |  \n",
      " |  __le__(self, value, /)\n",
      " |      Return self<=value.\n",
      " |  \n",
      " |  __len__(self, /)\n",
      " |      Return len(self).\n",
      " |  \n",
      " |  __lt__(self, value, /)\n",
      " |      Return self<value.\n",
      " |  \n",
      " |  __mul__(self, value, /)\n",
      " |      Return self*value.\n",
      " |  \n",
      " |  __ne__(self, value, /)\n",
      " |      Return self!=value.\n",
      " |  \n",
      " |  __rmul__(self, value, /)\n",
      " |      Return value*self.\n",
      " |  \n",
      " |  count(self, value, /)\n",
      " |      Return number of occurrences of value.\n",
      " |  \n",
      " |  index(self, value, start=0, stop=9223372036854775807, /)\n",
      " |      Return first index of value.\n",
      " |      \n",
      " |      Raises ValueError if the value is not present.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Class methods inherited from builtins.tuple:\n",
      " |  \n",
      " |  __class_getitem__(...) from builtins.type\n",
      " |      See PEP 585\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(time.localtime())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "ee9e65e1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "([1, 2, 3, 4], [3, 4, 5, 6]) <class 'tuple'> 2153806480064\n",
      "[1, 2, 3, 4] 2153805729472\n"
     ]
    }
   ],
   "source": [
    "tuple_test = ([1,2,3,4],[3,4,5,6])\n",
    "print(tuple_test,type(tuple_test),id(tuple_test))\n",
    "print(tuple_test[0],id(tuple_test[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "747f39ed",
   "metadata": {},
   "outputs": [],
   "source": [
    "tuple_test[0].append(100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "37f3f771",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "([1, 2, 3, 4, 100], [3, 4, 5, 6]) <class 'tuple'>\n",
      "[1, 2, 3, 4, 100] 2153805729472\n"
     ]
    }
   ],
   "source": [
    "print(tuple_test,type(tuple_test)),id(tuple_test)\n",
    "print(tuple_test[0],id(tuple_test[0]))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c7850ae2",
   "metadata": {},
   "source": [
    "## 2.集合（sets）\n",
    "> 1.基本概念\n",
    ">> 1.性质：无重复性\n",
    ">>\n",
    ">> 2.无序性\n",
    "> 2.一般方法\n",
    ">> 1.集合的运算：&，\n",
    ">> 2."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "3967b11e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['a', 'p', 'b', 'o']\n",
      "{'o', 'p', 'a', 'b'}\n"
     ]
    }
   ],
   "source": [
    "basket_list = ['a','p','b','o']\n",
    "basket_sets = {'a','p','b','o'}\n",
    "print(basket_list)\n",
    "print(basket_sets)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "687a7699",
   "metadata": {},
   "outputs": [],
   "source": [
    "舞蹈社 = {1801,1802,1803,1809,1811,1812}\n",
    "电竞社 = {1808,1822,1802,1801,1888,1899}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "718c22c5",
   "metadata": {},
   "source": [
    "* 集合的与运算，交集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "23399c74",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1801, 1802}"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社 & 电竞社"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0994bcef",
   "metadata": {},
   "source": [
    "* 集合的或运算，并集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "bb2a2d26",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1801, 1802, 1803, 1808, 1809, 1811, 1812, 1822, 1888, 1899}"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社 | 电竞社"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "ef86dfbb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(舞蹈社 | 电竞社)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "60ae7224",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1801, 1802, 1803, 1808, 1809, 1811, 1812, 1822, 1888, 1899}"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社.union(电竞社)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2489da50",
   "metadata": {},
   "source": [
    " # 3.字典（dict）\n",
    " > 1.字典的基本概念\n",
    " >>1.字典性质；\n",
    " >>> 1.无序性\n",
    " >>> 2.keys 是不可变性\n",
    " >>> 3.keys 是唯一性\n",
    " >>>\n",
    " >> 2.字典的形态\n",
    " >>\n",
    " > 2.字典的一般方法\n",
    " >> A.字典的创造\n",
    " >> B. 字典的函数和方法\n",
    " >>> 增加，删除，修改"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "64b85304",
   "metadata": {},
   "outputs": [],
   "source": [
    "网新二班 = {\n",
    "    18001:\"李\",\n",
    "    18002:\"刘\",\n",
    "    18003:\"韩\",\n",
    "    18004:\"郑\"\n",
    "    \n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "8e782f95",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{18001: '李', 18002: '刘', 18003: '韩', 18004: '郑'} <class 'dict'>\n"
     ]
    }
   ],
   "source": [
    "print(网新二班,type(网新二班))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "e5166a6a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'韩'"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 字典的取值：通过keys 进行字典取值，unlike 列表，元组和字符串通过index取值\n",
    "网新二班[18003]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "107836dd",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
